<template>
  <div>
    <div id="main" style="width: 600px; height: 400px; margin-left: 50px"></div>
    <div>
      <el-button type="primary" @click="transition">切换成饼图</el-button>
      <el-button type="primary" @click="jump">跳</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "BarView",

  data() {
    return {};
  },

  mounted() {
    this.barShow();
  },

  methods: {
    //显示柱状图
    barShow() {
      let dom = document.getElementById("main");
      let myCharts = this.$echarts.init(dom);
      let setOptions = {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: "bar",
            showBackground: true,
            backgroundStyle: {
              color: "rgba(180, 180, 180, 0.2)",
            },
          },
        ],
      };
      myCharts.setOption(setOptions);
    },

    // 跳转至另一图表
    transition() {
      this.$router.push("./formView");
    },

    jump() {
      this.$router.push("./jumpView");
    },
  },
};
</script>

<style lang="less" scoped>
</style>